<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/30 0030
 * Time: 下午 6:03
 */
//PHP 数值数组
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
echo '<br>';

//获取数组的长度 - count() 函数
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
echo '<br>';

//遍历数值数组
$cars=array("Volvo","BMW","Toyota");
$arrlength=count($cars);

for($x=0;$x<$arrlength;$x++)
{
    echo $cars[$x];
    echo "<br>";
}

//PHP 关联数组
//关联数组是使用您分配给数组的指定的键的数组。
//这里有两种创建关联数组的方法：
//$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
//or:
//$age['Peter']="35";
//$age['Ben']="37";
//$age['Joe']="43";
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
echo "<br>";

//遍历关联数组
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");

foreach($age as $x=>$x_value)
{
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "<br>";
}
?>